package plus.xj17520.org.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import plus.xj17520.org.domain.Department;
import plus.xj17520.org.service.IDeptService;
import plus.xj17520.base.query.DeptQuery;
import plus.xj17520.base.result.JSONResult;

/**
 * @projectName: Pethome5-6
 * @package: plus.xj17520.org.controller
 * @className: DeptController
 * @author: XiaoJue
 * @description: TODO
 * @date: 2022/5/7 1:16
 * @version: 1.0
 */
@RestController
@RequestMapping("dept")
@Api(value = "部门管理的接口文档",description = "部门管理的接口文档")
public class DeptController {
    @Autowired
    IDeptService deptService;

    @ApiOperation(value = "查询单个部门对象",notes = "此方法的具体说明在这里描述")
    @GetMapping("findOne/{id}")
    public JSONResult findOne(@ApiParam(value = "部门id") @PathVariable Long id){
        return deptService.findOne(id);
    }

    @ApiOperation(value = "查询部门的所有对象",notes = "此方法的具体说明在这里描述")
    @PostMapping("all")
    public JSONResult findAll(){
        return deptService.findAll();
    }

    @ApiOperation(value = "新增一个部门对象",notes = "此方法的具体说明在这里描述")
    @PostMapping("add")
    public JSONResult add(@RequestBody Department department){
        return deptService.addOrUpdate(department);
    }

    @ApiOperation(value = "删除一个部门对象",notes = "此方法的具体说明在这里描述")
    @GetMapping("delete/{id}")
    public JSONResult delete(@ApiParam(value = "部门实例对象的id") @PathVariable Long id){
        return deptService.delete(id);
    }

    @ApiOperation(value = "修改一个部门对象",notes = "此方法的具体说明在这里描述")
    @PostMapping("update")
    public JSONResult update(@RequestBody Department department){
        return deptService.addOrUpdate(department);
    }

    @ApiOperation(value = "分页，高级查询,查询所有",notes = "此方法的具体说明在这里描述")
    @PostMapping("query")
    public JSONResult query(@RequestBody DeptQuery deptQuery){
        return deptService.deptPageList(deptQuery);
    }

    @ApiOperation(value = "批量删除",notes = "此方法的具体说明在这里描述")
    @PostMapping("batchDelete")
    public JSONResult batchDelete(@RequestBody DeptQuery deptQuery){
        return deptService.batchDelete(deptQuery);
    }

}
